﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Build.Evaluation;
using System.IO;

namespace Aceso.Server.DAL
{
    public class MergeClass
    {
        public void WriteFile()
        {
            DirectoryInfo baseDir = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.Parent;
            string projPath = baseDir.FullName + @"\Aceso.Server.DAL\Aceso.Server.DAL.csproj";
            string path = System.Environment.CurrentDirectory;
            ProjectCollection pc = new ProjectCollection();
            Project project = pc.LoadProject(projPath);
            //获取所有编译项
            IEnumerable<ProjectItem> compileGroups = project.AllEvaluatedItems.Where(e => e.ItemType == "Compile");
            //建立关联
            ProjectItem includeGens = compileGroups.Where(e => e.EvaluatedInclude == @"outPath\IBasic_DealerInfoRepository.generated.cs").FirstOrDefault();
            if(includeGens != null && includeGens.GetMetadata("DependentUpon") == null)
            {
                includeGens.SetMetadataValue("DependentUpon", "IBasic_DealerInfoRepository.cs");
            }
            project.Save();
        }
    }
}
